<?PHP
	require 'config.php';
	require 'modifyImage.php';
	require 'CyrillicEncoder.php';
	
	//connecting to DB
	$vLink = mysql_connect($DBServer, $DBUser, $DBPassword);
	if(!$vLink) 
		die(mysql_error());
	
	//setting session encoding
	mysql_select_db($DBName, $vLink);	
	mysql_query("SET NAMES 'cp1251';", $vLink);
	mysql_query("SET CHARACTER SET 'cp1251';", $vLink);
	mysql_query("SET SESSION collation_connection = 'cp1251_general_ci';", $vLink);
	
	//retrieving params
	$ID = $_GET['id'];
	$OwnerID = $_GET['owner_id'];
	$OwnerType = $_GET['owner_type'];
	$Order = $_GET['order'];
	$Description = htmlspecialchars($_GET['description'], ENT_QUOTES);
	//retrieving file modifications flags
	$Replace = $_GET['replace'];
	$Rotation = $_GET['rotation'];
	
	//sending query
	$vQuery = 'UPDATE dikar2011_photos SET id_obj="' . $OwnerID . '", owner="' . $OwnerType . '", ord="' . $Order . '", description= "' . $Description . '" WHERE id="' . $ID . '"';
	mysql_query($vQuery);
	mysql_close($vLink);
	
	//file(s) will be modified only if DB update query executed successfully	
	if(isset($Rotation))
	{
		DoRotate($ID, $OwnerType, $Rotation, $imagesFolders, $imagesPrefixes);
		$Rotation = $ID .' - '. $OwnerType;
	}
	if(isset($Replace))
	{
		$vReplaceParams = explode(',', $Replace);
		DoReplace($ID, $vReplaceParams[0], $vReplaceParams[1], $imagesFolders, $imagesPrefixes);
	}	
	//printing update result for AS side
	echo '1, rotation = ' . $Rotation;
?>